#include "qdialoglocate.h"
#include "ui_qdialoglocate.h"
#include <QMessageBox>
#include "mainwindow.h"

QDialogLocate::QDialogLocate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QDialogLocate)
{
    ui->setupUi(this);
}

QDialogLocate::~QDialogLocate()
{
    QMessageBox::information(this, "", "单元格定位对话框已退出");
    delete ui;
}

void QDialogLocate::setRange(int rows, int cols)
{
    ui->spinBoxRow->setRange(0, rows - 1);
    ui->spinBoxColumn->setRange(0, cols - 1);
}

void QDialogLocate::setValue(int row, int col)
{
    ui->spinBoxRow->setValue(row);
    ui->spinBoxColumn->setValue(col);
}

void QDialogLocate::closeEvent(QCloseEvent *event)
{
    MainWindow *paraW = (MainWindow *)parentWidget();
    paraW->setActLocateEnable(true);
    paraW->setDialogLocaltNull();
}

void QDialogLocate::on_btnSetText_clicked()
{
    int row  = ui->spinBoxRow->value();
    int col = ui->spinBoxColumn->value();
//    MainWindow *paraW = (MainWindow *)parentWidget();
//    paraW->setCellText(row, col, ui->lineEdit->text());
    emit changeCellText(row, col, ui->lineEdit->text());

    if(ui->chkBoxRow->isChecked())
        ui->spinBoxRow->setValue(ui->spinBoxRow->value() + 1);
    if(ui->chkBoxCol->isChecked())
        ui->spinBoxColumn->setValue(ui->spinBoxColumn->value() + 1);
}
